import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/home' },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '主页'
    },
    component: Home
  },
  {
    path: '/post',
    name: 'post',
    meta: {
      title: '文章管理'
    },
    component: () => import('../views/Post.vue')
  },
  {
    path: '/markdown/:id',
    name: 'markdown',
    meta: {
      title: '编辑文章'
    },
    props (route) {
      const props = { ...route.params }
      // to number
      props.id = +props.id
      return props
    },
    component: () => import('../views/Markdown.vue')
  },
  {
    path: '/category',
    name: 'category',
    meta: {
      title: '分类管理'
    },
    component: () => import('../views/Category.vue')
  },
  {
    path: '/tag',
    name: 'tag',
    meta: {
      title: '标签管理'
    },
    component: () => import('../views/Tag.vue')
  },
  {
    path: '/comment',
    name: 'comment',
    meta: {
      title: '评论管理'
    },
    component: () => import('../views/Comment.vue')
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      direct: true
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
